package org.ielse.frame.test.fragment;

import org.ielse.frame.BaseFragment;
import org.ielse.frame.R;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;

public class RightMenuFragment extends BaseFragment {

	@Override public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	private LinearLayout layContainer;

	@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_right_menu, container, false);

		layContainer = (LinearLayout) view.findViewById(R.id.lay_container);
		
		resetContentAnimation();
		return view;
	}

	public void startContentAnimation() {
			final DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
			for (int i = 0; i < layContainer.getChildCount(); i++) {
				final View child = layContainer.getChildAt(i);
				ObjectAnimator anim1 = ObjectAnimator.ofFloat(child, "translationX", layContainer.getWidth(), 0);
				ObjectAnimator anim2 = ObjectAnimator.ofFloat(child, "alpha", 0, 1);
				AnimatorSet set = new AnimatorSet();
				set.play(anim1).with(anim2);
				set.setInterpolator(decelerateInterpolator);
				set.setDuration(320);
				set.setStartDelay(i * 100);
				set.start();
		}
	}

	public void resetContentAnimation(){
		for (int i = 0; i < layContainer.getChildCount(); i++) {
			View child = layContainer.getChildAt(i);
			child.setAlpha(0);
		}
	}
	
}
